<?php

function submit($ch , $filepath) {
	curl_setopt($ch, CURLOPT_URL, "http://localhost/lz/services/grading/grade?clientid=1&clienttoken=1");
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_POST, true);
	
	$data = array(
		'GradeRequest[evaluationset_id]' => 10,
		'GradeRequest[mode]' => 0,
		'GradeRequest[submitter_id]' => "Karol Danutama"
	);
	
	$data['GradeRequest[file]'] = "@" . $filepath;
	
	curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
	$output = curl_exec($ch);
	$info = curl_getinfo($ch);
	
	echo $output . "\n";
}

function securityTest($ch) {
	for ($i = 0 ; $i <= 100 ; $i++) {
		submit($ch , "answer.zip");
		usleep(500000);
	}
}

function interactiveTest($ch , $period , $frequency) {
	echo "Starting interactive scalability test for $frequency source code/min, $period minutes\n==============================\n";
	
	$interval = 60 * 1000000 / $frequency;
	$num = $frequency * $period;
	
	echo "Interval : " . $interval . " num of source code " . $num . "\n";
	for ($i = 0 ; $i < $num ; $i++) {
		submit($ch , "answer.zip");
		usleep($interval);
	}
	
	echo "End of interactive scalability test\n==============================\n";
}

$ch = curl_init();
echo $ch . "\n";

/*interactiveTest($ch , 3 , 10);
sleep(30);
interactiveTest($ch , 3 , 20);
sleep(30);
interactiveTest($ch , 3 , 40);
sleep(30);
interactiveTest($ch , 3 , 60);
sleep(120);
interactiveTest($ch , 3 , 90);
sleep(120);*/
interactiveTest($ch , 3 , 120);


curl_close($ch);

/*
interactiveTest($ch , 3 , 10); --> 997 - 1026
interactiveTest($ch , 3 , 20); --> 1027 - 1086
interactiveTest($ch , 3 , 40); --> 1087 - 1206
interactiveTest($ch , 3 , 60); --> 1207 - 1386
interactiveTest($ch , 3 , 90); --> 1387 - 1656
interactiveTest($ch , 3 , 120); --> 1657 - 2016
 * 
 * */

?>
